import request from '@/utils/axios'
import qs from 'qs'

export type SensitiveWordType = {
  id: number | undefined
  name: string
  status: number
  remark: string
  tags: string[]
  create_time?: Date
}

export interface SensitiveWordPageReqType extends PageParam {
  name?: string
  tag?: string
  status?: number
  create_time?: Date[]
}

export interface SensitiveWordCheckReqType {
  text?: string
  tag?: string[]
}

/**
 * 敏感词接口
 */
export const SensitiveWordApi = {
  // 新增
  create: (data: SensitiveWordType) => {
    return request.post({ url: '/system/sensitive-word/create', data, is_mock: true })
  },
  // 修改
  update: (data: SensitiveWordType) => {
    return request.put({ url: '/system/sensitive-word/update', data, is_mock: true })
  },
  // 删除
  delete: (id: number | string) => {
    return request.delete({ url: '/system/sensitive-word/delete?id=' + id, is_mock: true })
  },
  // 查询详情
  detail: (id: number | string) => {
    return request.get({ url: '/system/sensitive-word/detail?id=' + id, is_mock: true })
  },
  // 查询分页列表
  page: (params: SensitiveWordPageReqType) => {
    return request.get({ url: '/system/sensitive-word/page', params, is_mock: true })
  },
  // 导出
  export: (params: SensitiveWordPageReqType) => {
    return request.get({ url: '/system/sensitive-word/export', params, is_mock: true })
  },
  // 获取敏感词标签数组
  tag: () => {
    return request.get({ url: '/system/sensitive-word/tags-list', is_mock: true })
  },
  // 获取文本包含的不合法敏感词数组
  validate: (params: SensitiveWordCheckReqType) => {
    return request.get({ url: '/system/sensitive-word/validate-text?' + qs.stringify(params, { arrayFormat: 'repeat' }), is_mock: true })
  }
}
